﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Test_Input : MonoBehaviour
{
    //演示获取鼠标输入
    private void Update1()
    {
        if (Input.GetMouseButtonDown(0))
        {
            print("按下鼠标左键");
            transform.position = transform.position + new Vector3(0, 1, 0);
        }
        if (Input.GetMouseButtonDown(1))
        {
            print("按下鼠标右键");
        }
        if (Input.GetMouseButton(0))
        {
            print("按住鼠标左键");
            print(Input.mousePosition);//输出鼠标位置
        }
    }

    //演示获取按键输入
    private void Update2()
    {
        if (Input.GetKeyDown(KeyCode.W))
        {
            print("按下W");
        }
        if (Input.GetKey(KeyCode.W))
        {
            print("按住W");
        }
        if (Input.GetKeyUp(KeyCode.W))
        {
            print("抬起W");
        }
    }

    //演示获取虚拟按键
    private void Update3()
    {
        if (Input.GetButtonDown("Skill1"))
        {
            print("按下了开火1");
        }
    }

    //演示获取虚拟轴   水平:Horizontal   垂直:Vertical
    private void Update4()
    {
        //获取水平轴  A:-1  D:1    都不按返回0   加Raw
        float h = Input.GetAxisRaw("Horizontal");//轴的名字区分大小写,不要写错
        float v = Input.GetAxis("Vertical");
        Vector3 direction = new Vector3(h, 0, v).normalized;  //normalized 让向量长度变为1  方向不变
        transform.Translate(direction * Time.deltaTime * 5);//沿着direction方向每秒5米运动
    }

    private void Update()
    {
        if (Input.GetMouseButton(0))
        {
            float x = Input.GetAxis("Mouse X");//鼠标在水平方向的滑动增量(相对于上一帧的变化)
            print(x);
        }
    }
}